package com.quan.mobile.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.quan.common.base.bean.ResultBean;
import com.quan.common.core.BaseController;

import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;

@RestController
@RequestMapping("/weixin/api")
public class WeixinApiController extends BaseController {
	
	@Autowired
	private WxMpService wxMpService;

	@GetMapping(value = "/getJsapiTicket")
	public Object getJsapiTicket(String url) {
		try {
			String requestUrl = request.getHeader("Referer") ;
			WxJsapiSignature signature = this.wxMpService.createJsapiSignature(requestUrl);
			return ResultBean.ok(signature) ;
		} catch (WxErrorException e) {
			e.printStackTrace();
		}
		return ResultBean.failure("调用jsapi时所需要的签名失败") ;
		
	}
	
}
